const path = require('path');
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const ignorePlugin = new webpack.IgnorePlugin(/\.\/src\/jquery.js/);

module.exports = {
    //入口文件
    entry: './src/index.jsx',
    //输出文件
    output: {
        path: path.resolve(__dirname, 'dist'),
        //公共路径
        publicPath: "/dist/",
        //引入文件的名称
        filename: 'js/index.jsx'
    },
    //配置资源目录
    resolve: {
        alias: {
            component: path.resolve(__dirname, 'src/js/component'),
            util: path.resolve(__dirname, 'src/util'),
            static: path.resolve(__dirname, 'src/static'),
        }
    },
    module: {
        //解析jsx语法的
        rules: [
            {
                test: /(\.jsx$)|(\.js$)/,
                exclude: /(node_modules)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['env', 'react'],
                        plugins: [
                            ["import", {"libraryName": "ant-mobile", "libraryDirectory": "lib"}, "ant"]
                        ]
                    },

                }
            },
            //解析css
            {
                test: /\.css$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: "css-loader"
                })
            },
            //解析sacss
            {
                test: /\.scss$/,
                use: [
                    "style-loader", // creates style nodes from JS strings
                    "css-loader", // translates CSS into CommonJS
                    "sass-loader" // compiles Sass to CSS
                ]
            },
            //打包图片资源
            {
                test: /\.(png|jpg|gif)$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 8192,
                            name: 'resource/[name].[ext]'
                        }
                    }
                ]
            },
            //打包文字资源
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 8192,
                            name: 'resource/[name].[ext]'
                        }
                    }
                ]
            }
        ]
    },
    plugins: [
        //html插件模版
        new HtmlWebpackPlugin({
            template: './src/index.html',
            favicon: "./src/favicon.ico",
            hash: true
        }),
        new ExtractTextPlugin("css/[name].css"),
        //抽取公共模块
        new webpack.optimize.CommonsChunkPlugin({
            name: 'common',
            filename: "js/base.js"
        }),
        ignorePlugin
    ],

    /*devServer: {
        port: "8086",
        historyApiFallback: {
            index: "/dist/index.html"
        },
        proxy: {
            '/weather': {
                target: 'http://10.135.30.206:8100',
                changeOrigin: true
            },
            '/api': {
                target: 'http://10.135.30.206:8100',
                changeOrigin: true
            },
            '/common': {
                target: 'http://localhost:8080',
                changeOrigin: true
            },
            '/detail': {
                target: 'http://localhost:8080',
                changeOrigin: true
            }
        }

    }*/
};